import storage from '@/utils/storage'
import constant from '@/utils/constant'
import {
    configData
} from '@/api/config.js'
 
const data = {
    state: {
        // 市场列表
        marketList: storage.get(constant.marketList),
        // 企业行业列表
        industryList: storage.get(constant.industryList),
    },
 
    mutations: {
        SET_MARKETS: (state, marketList) => {
            state.marketList = marketList
            storage.set(constant.marketList, JSON.stringify(marketList))
            
        },
        SET_INDUSTRYS: (state, industryList) => {
            state.industryList = industryList
            storage.set(constant.industryList, JSON.stringify(industryList))
        },
        
    },
 
    actions: {
        // 系统配置数据
        ConfigData({
            commit
        }) {
            return new Promise((resolve, reject) => {
                configData().then(respones => {
                    commit('SET_MARKETS', respones.data.marketList)
                    commit('SET_INDUSTRYS', respones.data.industryList)
                    resolve()
                }).catch(error => {
                    reject(error)
                })
            })
        },
    }
}
 
export default data